<?php
if(!isset($_SESSION)) 
{ 
	session_start(); 
} 
set_time_limit(0);
ini_set("memory_limit", "64M");
include '../content-home/showscreen.php';


	include("zip_min.inc");
	
	function GetImageFromUrl($link)
{
	$ch = curl_init();
 
	curl_setopt($ch, CURLOPT_POST, 0);
 
	curl_setopt($ch,CURLOPT_URL,$link);
 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
	$result=curl_exec($ch);

	curl_close($ch);
 	
	return $result;
	
}


	//$zipfile = new zipfile();
	if(isset($_REQUEST['checkCarnum']) and is_array($_REQUEST['checkCarnum'])){
		$zipfile = new zipfile();
		
		$mylistcarnum = $_SESSION['mylistcarnum'];
		$url = new showscreen();
		$listchc = $_REQUEST['checkCarnum'];
		
		foreach ($listchc as $key => $value) {
			$row = $mylistcarnum[$key];
	        //array($row[id],$row[name],$row[car_datetime],$row[carnumber],$row[host],$row[filename],$row[isReg]);
	        $id = $row[0];
			$name = $row[1];
			$car_datetime = $row[2];
			$carnumber = $row[3];
			$host = $row[4];
			$filename1 = $row[5];
			$isReg = $row[6];
			
			$first = substr($filename1, 0,18);
			$middle = substr($filename1, 18,3);
			$last = substr($filename1, 21);
			$filename2 = $first.'002'.$last;
			$filename3 = $first.'003'.$last;
			//echo $filename1."<br>";echo $filename2."<br>";echo $filename3."<br>";
		
	        $url->GetPath($id,$name,$car_datetime,$carnumber,$host,$filename1,$isReg);
	        $imageData=GetImageFromUrl($url->image);
	        $filename= str_replace(" ","+",$filename1);
	        $zipfile -> addFile($imageData, $filename);
	        
	        $url->GetPath($id,$name,$car_datetime,$carnumber,$host,$filename2,$isReg);
	        $imageData=GetImageFromUrl($url->image);
	        $filename= str_replace(" ","+",$filename2);
	        $zipfile -> addFile($imageData, $filename);
	        
	        $url->GetPath($id,$name,$car_datetime,$carnumber,$host,$filename3,$isReg);
	        $imageData=GetImageFromUrl($url->image);
	        $filename= str_replace(" ","+",$filename3);
	        $zipfile -> addFile($imageData, $filename);
		}
		//unset($_SESSION['zipselect']);
		//echo $zipfile -> file();
		header("Content-type: application/zip");
		//header("Content-type: application/octet-stream");
		header("Content-disposition: attachment; filename=Images.zip");
		header("Pragma: no-cache"); 
		header("Expires: 0"); 
		echo $zipfile -> file();
	}
	//$url=$_REQUEST['url'];
	//$name=$_REQUEST['name'];
	
	//$fileonserver = split(';',$url);
	//$filename = split(';',$name);
	
	//http://175.126.145.187/recogsave/2012/20121207/18/39/121207_183927_407_002_++++24%EB%A7%885558_r0009_c9999_1234.jpg
	//for ($i = 1; $i < sizeof($fileonserver); $i++) {

		//$imageData1=GetImageFromUrl($fileonserver[$i]);
		//$filename1= str_replace(" ","+",$filename[$i]);
		//$zipfile -> addFile($imageData1, $filename1);
		//$zipfile -> addFile(file_get_contents($imageData1), $filename1);
		
	//}
	//$imageData1=GetImageFromUrl("http://175.126.145.187/recogsave/2012/20121207/18/39/121207_183927_407_002_++++24%EB%A7%885558_r0009_c9999_1234.jpg");
	//$filename1= str_replace(" ","+","test.jpg");
	//$zipfile -> addFile($imageData1, $filename1);
		
	
	
?>